package com.qlh.composewidget

import android.os.Bundle
import android.util.Log
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.blankj.utilcode.util.Utils
import com.feeyo.groundservice.base_util.FyLog
import com.feeyo.groundservice.base_util.SuccessCallback
import com.feeyo.groundservice.base_util.getRouterPath
import com.feeyo.groundservice.base_util.upgrade.UpgradeInfo
import com.feeyo.groundservice.base_util.upgrade.UpgradeUtil
import com.feeyo.groundservice.checkin.base.CheckInModuleInit
import com.feeyo.groundservice.checkin.constant.CheckInPath
import com.feeyo.groundservice.composewidget.usage.BannerActivity
import com.feeyo.groundservice.composewidget.usage.ButtonActivity
import com.feeyo.groundservice.composewidget.usage.ComposePagerActivity
import com.feeyo.groundservice.composewidget.usage.DateSelectorActivity
import com.feeyo.groundservice.composewidget.usage.DragListActivity
import com.feeyo.groundservice.composewidget.usage.FlowLayoutActivity
import com.feeyo.groundservice.composewidget.usage.ImageViewerActivity
import com.feeyo.groundservice.composewidget.usage.MenuFabActivity
import com.feeyo.groundservice.composewidget.usage.ProcessActivity
import com.feeyo.groundservice.composewidget.usage.RefreshActivity
import com.feeyo.groundservice.composewidget.usage.SlideBarActivity
import com.feeyo.groundservice.composewidget.usage.SlideMenuActivity
import com.feeyo.groundservice.composewidget.usage.SwitchActivity
import com.feeyo.groundservice.composewidget.usage.TextFieldActivity
import com.feeyo.groundservice.composewidget.usage.base.BaseComposeActivity
import com.feeyo.groundservice.composewidget.view.title_bar.CommonTitleView
import com.feeyo.groundservice.recordnfc.base.RecorderCardModuleInit
import com.feeyo.groundservice.recordnfc.constant.AIRPORT
import com.feeyo.groundservice.recordnfc.constant.IATAS
import com.feeyo.groundservice.recordnfc.constant.RecordCardPath
import com.feeyo.groundservice.recordnfc.constant.TOKEN
import com.feeyo.groundservice.recordnfc.constant.UID
import com.feeyo.groundservice.usbserial.useage.UsbSerialActivity
import com.feeyo.groundservice.zxing.ScanCodeListener
import com.feeyo.groundservice.zxing.ScanCodeType
import com.feeyo.groundservice.zxing.ScanCodeUtil
import com.feeyo.lib_baidutts.voice.SpeechManager
import com.feeyo.location.GPSUtil
import com.qlh.composewidget.h5record.H5RecordActivity
import com.qlh.composewidget.useage.TestEasyPhoto
import com.qlh.composewidget.useage.TestPictureSelector

/**
 *作者：QLH on 2023-08-05
 *描述：compose库组件功能测试入口
 */
class ComposeTestEntryActivity : BaseComposeActivity() {

    private val buttons = listOf(
        "Banner功能" to BannerActivity::class.java,
        "ViewPager功能" to ComposePagerActivity::class.java,
        "FlowLayout功能" to FlowLayoutActivity::class.java,
        "带菜单的Fab" to MenuFabActivity::class.java,
        "侧滑菜单SlideMenu" to SlideMenuActivity::class.java,
        "图片预览" to ImageViewerActivity::class.java,
        "值选择器" to DateSelectorActivity::class.java,
        "刷新组件" to RefreshActivity::class.java,
        "输入框" to TextFieldActivity::class.java,
        "进度条" to ProcessActivity::class.java,
        "滑块" to SlideBarActivity::class.java,
        "Usb串口测试" to UsbSerialActivity::class.java,
        "拍照相册" to TestEasyPhoto::class.java,
        "拍照相册视频录音" to TestPictureSelector::class.java,
        "Switch、Tab切换" to SwitchActivity::class.java,
        "自定义按钮" to ButtonActivity::class.java,
        "h5录音" to H5RecordActivity::class.java,
        "发送广播到第三方APP" to SendBroadcastActivity::class.java,
        "拖拽列表" to DragListActivity::class.java
    )

    private lateinit var upgradeUtil:UpgradeUtil

    init {
        SpeechManager.getInstance().init(Utils.getApp())
        RecorderCardModuleInit().apply {
            onInitDelay(Utils.getApp())
            onInitParams(
                "http://112.126.95.197/dispatch-api/", R.color.blue_2E76EE
            )
        }

        CheckInModuleInit().apply {
            onInitDelay(Utils.getApp())
            onInitParams(
                "http://112.126.95.197/dispatch-api/", R.color.blue_2E76EE
            )
        }

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        upgradeUtil = UpgradeUtil(this)
        setContent {
            LazyColumn(modifier = Modifier.fillMaxSize()) {
                item {
                    Column {
                        CommonTitleView(
                            "测试的",
                        )
                    }
                }
                items(buttons) {
                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = { jump(it.second as Class<out AppCompatActivity>) }) {
                        Text(text = it.first)
                    }
                }
                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            SpeechManager.userLocalSystem = false
                            SpeechManager.getInstance().speakAuto(
                                "测试语音播报的，优先使用的是百度语音播报引擎，3U7862航班，机位是12",
                                ""
                            )
                        }) {
                        Text(text = "优先百度播报")
                    }
                }

                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            SpeechManager.userLocalSystem = true
                            SpeechManager.getInstance().speakAuto(
                                "测试语音播报的，优先使用的是系统语音播报引擎，3U7862航班，机位是12",
                                ""
                            )
                        }) {
                        Text(text = "优先系统播报")
                    }
                }

                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            GPSUtil.isOpenLocationPermission(object : SuccessCallback {})
                        }) {
                        Text(text = "测试GPS定位权限")
                    }
                }

                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            ScanCodeUtil.scanCode(
                                ScanCodeType.MIXED_CONTINUOUS,
                                "连续扫码",
                                object : ScanCodeListener {
                                    override fun onScanCodeSuccess(result: String, format: String) {
                                        FyLog.e("scanCode", result)
                                    }
                                })
                        }) {
                        Text(text = "连续扫码")
                    }
                }

                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            ScanCodeUtil.scanCode(
                                ScanCodeType.MIXED,
                                "单次扫码",
                                object : ScanCodeListener {
                                    override fun onScanCodeSuccess(result: String, format: String) {
                                        FyLog.e("scanCode", result)
                                    }
                                })
                        }) {
                        Text(text = "单次扫码")
                    }
                }

                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            ScanCodeUtil.scanCode(
                                ScanCodeType.QRCODE,
                                "扫描二维码",
                                object : ScanCodeListener {
                                    override fun onScanCodeSuccess(result: String, format: String) {
                                        FyLog.e("scanCode", result)
                                    }
                                })
                        }) {
                        Text(text = "扫描二维码")
                    }
                }

                item {

                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            ScanCodeUtil.scanCode(
                                ScanCodeType.BARCODE,
                                "扫描条形码",
                                object : ScanCodeListener {
                                    override fun onScanCodeSuccess(result: String, format: String) {
                                        FyLog.e("scanCode", result)
                                    }
                                })
                        }) {
                        Text(text = "扫描条形码")
                    }
                }

                item {
                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            RecordCardPath.RecorderCardActivity.getRouterPath()
                                .withObject(IATAS, listOf("SHE", "SHE"))
                                .withString(AIRPORT, "SHE")
                                .withString(UID, "10")
                                .withString(TOKEN, "64b589c1-3a8e-4839-b77b-60ad6acd35bb")
                                .navigation()
                        }
                    ) {
                        Text(text = "录卡")
                    }
                }

                item {
                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            CheckInPath.CheckInActivity.getRouterPath()
                                .navigation()
                        }
                    ) {
                        Text(text = "值机")
                    }
                }

                item {
                    Button(
                        modifier = Modifier.padding(0.dp),
                        onClick = {
                            upgradeUtil.checkUpdate(
                                UpgradeInfo(
                                    "升级测试",
                                    "升级测试一下",
                                    "https://down.variflight.com/adep/dispatch-pvg-prod.apk",
                                    false
                                )
                            )
                        }
                    ) {
                        Text(text = "Apk升级测试")
                    }
                }
            }
        }

        val str = intent.getStringExtra("task") ?: "没有数据"
        Log.e("收到的数据", str)

    }

}